﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.Cache
{
    /// <summary>
    /// 通用缓存接口
    /// </summary>
    public interface ICache
    {
        /// <summary>
        /// 增加新的缓存项
        /// </summary>
        /// <param name="key">缓存key</param>
        /// <param name="value">缓存值</param>
        void Add(string key, object value);

        /// <summary>
        /// 增加新的缓存项，提供过期时间
        /// </summary>
        /// <param name="key">缓存key</param>
        /// <param name="value">缓存值</param>
        /// <param name="ts">过期时间</param>
        void Add(string key, object value, TimeSpan ts);

        /// <summary>
        /// 增加新的缓存项，需要提供缓存命名空间
        /// </summary>
        /// <param name="ns">命名空间值</param>
        /// <param name="key">缓存key</param>
        /// <param name="value">缓存值</param>
        void Add(string ns, string key, object value);

        /// <summary>
        /// 增加新的缓存项，需要提供命名空间与过期时间
        /// </summary>
        /// <param name="ns">命名空间值</param>
        /// <param name="key">缓存key</param>
        /// <param name="value">缓存值</param>
        /// <param name="ts">过期时间</param>
        void Add(string ns, string key, object value, TimeSpan ts);

        /// <summary>
        /// 获取缓存对象 
        /// </summary>
        /// <param name="key">缓存key</param>
        /// <returns>缓存值</returns>
        object Get(string key);

        /// <summary>
        /// 获取缓存对象
        /// </summary>
        /// <param name="ns">缓存命名空间</param>
        /// <param name="key">缓存key</param>
        /// <returns>缓存值</returns>
        object Get(string ns, string key);

        /// <summary>
        /// 检查缓存是否存在
        /// </summary>
        /// <param name="ns">缓存命名空间</param>
        /// <param name="key">缓存key</param>
        /// <returns>检查结果</returns>
        bool Exists(string ns, string key);

        /// <summary>
        /// 检查缓存是否存在
        /// </summary>
        /// <param name="key">缓存key</param>
        /// <returns>检查结果</returns>
        bool Exists(string key);

        /// <summary>
        /// 删除指定的缓存对象
        /// </summary>
        /// <param name="key">缓存key</param>
        void Remove(string key);

        /// <summary>
        /// 删除指定的缓存对象
        /// </summary>
        /// <param name="ns">缓存命名空间</param>
        /// <param name="key">缓存key</param>
        void Remove(string ns, string key);

        /// <summary>
        /// 清除给定命名空间下的所有缓存
        /// </summary>
        /// <param name="ns">命名空间</param>
        void Clear(string ns);

        /// <summary>
        /// 清除系统中的所有缓存
        /// </summary>
        void Clear();
    }
}
